import {reqGetSearchInfo} from "@/api";
// search模块小仓库

const state = {
    searchList: {}
}
const actions = {
    async getSearchList(context, params = {}) {
        const result = await reqGetSearchInfo(params);
        if (result.code === 200) {
            context.commit('GETSEARCHLIST', result.data)
        }
    }
}
const mutations = {
    GETSEARCHLIST(state, searchList) {
        state.searchList = searchList
    }
}
// 计算属性，简化数据而生
const getters = {
    goodsList(state) {
        // 返回数据，如果是空的就返回一个[]数组
        return state.searchList.goodsList || []
    },
    attrsList(state) {
        return state.searchList.attrsList || []
    },
    trademarkList(state) {
        return state.searchList.trademarkList || []
    },
    total() {
        return state.searchList.total || []
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}